package com.example.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.bean.QuestionBean;
import com.example.myrobot.R;

import java.util.List;

public class QuestionAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<QuestionBean> mData;
    public QuestionAdapter(Context context, List<QuestionBean> data) {
        this.mInflater = LayoutInflater.from(context);
        this.mData = data;
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_question,parent,false);
            holder.tvQuestion = convertView.findViewById(R.id.tv_question);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        QuestionBean questionBean = mData.get(position);
        holder.tvQuestion.setText((position + 1) + ". " + questionBean.getQuestion());
        return convertView;
    }

    private class ViewHolder {
        TextView tvQuestion;
    }
}